package com.hongxun.project.assets.pPoint.service;

import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.hongxun.project.assets.pPoint.mapper.PPointMapper;
import com.hongxun.project.assets.pPoint.domain.PPoint;
import com.hongxun.project.assets.pPoint.service.IPPointService;
import com.hongxun.common.utils.text.Convert;

/**
 * 点位采集基础 服务层实现
 *
 * @author hongxun
 * @date 2019-03-19
 */
@Service
public class PPointServiceImpl implements IPPointService {
    @Autowired
    private PPointMapper pPointMapper;

    /**
     * 查询点位采集基础信息
     *
     * @param id 点位采集基础ID
     * @return 点位采集基础信息
     */
    @Override
    public PPoint selectPPointById(String id, String taskId) {
        return pPointMapper.selectPPointById(id, taskId);
    }

    @Override
    public PPoint selectPPointByIdForState(String id, String taskId) {
        return pPointMapper.selectPPointByIdForState(id, taskId);
    }

    /**
     * 查询点位采集基础列表
     *
     * @param pPoint 点位采集基础信息
     * @return 点位采集基础集合
     */
    @Override
    public List<PPoint> selectPPointList(PPoint pPoint) {
        return pPointMapper.selectPPointList(pPoint);
    }

    @Override
    public List<PPoint> selectlistIsPole(PPoint pPoint) {
        return pPointMapper.selectlistIsPole(pPoint);
    }

    /**
     * 新增点位采集基础
     *
     * @param pPoint 点位采集基础信息
     * @return 结果
     */
    @Override
    public int insertPPoint(PPoint pPoint) {
        pPoint.setId(UUID.randomUUID().toString());
        return pPointMapper.insertPPoint(pPoint);
    }

    /**
     * 修改点位采集基础
     *
     * @param pPoint 点位采集基础信息
     * @return 结果
     */
    @Override
    public int updatePPoint(PPoint pPoint) {
        return pPointMapper.updatePPoint(pPoint);
    }

    /**
     * 删除点位采集基础对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deletePPointByIds(String ids) {
        return pPointMapper.deletePPointByIds(Convert.toStrArray(ids));
    }


    @Override
    public int deletePPointByIdsAndTaskIds(String ids, String taskIds) {
        return pPointMapper.deletePPointByIdsAndTaskIds(Convert.toStrArray(ids), Convert.toStrArray(taskIds));
    }


    @Override
    public void insertOrReplaceOrDelete(List<PPoint> entities) {
        for (PPoint d : entities) {
//			if (d.getDatastate().equals("删除")) {
//				pPointMapper.deletePPointByIdsAndTaskIds(Convert.toStrArray(d.getId()) , Convert.toStrArray(d.getTaskId()));
//			} else {
            PPoint pPoint = pPointMapper.selectPPointById(d.getId(), d.getTaskId());
            if (pPoint == null) {
                pPointMapper.insertPPoint(d);
            } else {
                pPointMapper.updatePPoint(d);
            }
//			}
        }
    }

    @Override
    public int selectCoutByPoleHeightOrCrossType(PPoint pPoint) {
        return pPointMapper.selectCoutByPoleHeightOrCrossType(pPoint);
    }

}
